import axios from "axios";
import { BASE_URL, TIMEOUT } from "./config";

class ITCRequest {
  constructor (baseURL, timeout) {
    this.instance = axios.create({
      baseURL,
      timeout
    })
    // 请求拦截
    this.instance.interceptors.request.use((config) => {
      return config
    })
    // 响应拦截
    this.instance.interceptors.response.use((response) => {
      return response.data
    }, error => {
      return error
    })
  }

  request (config) {
    return this.instance.request(config)
  }

  get (config) {
    return this.request({ ...config, method: 'get' })
  }

  post (config) {
    return this.request({ ...config, method: 'post' })
  }
}
const instance = new ITCRequest(BASE_URL, TIMEOUT)

export default instance